#!/bin/sh

GROUPFILE=$1
USERFILE=$2

if [ "$GROUPFILE" == "" ]; then
 GROUPFILE=./sysgroups.txt
fi

if [ "$USERFILE" == "" ]; then
 USERFILE=./sysusers.txt
fi

while IFS= read -r LINE
do
  NAME=echo $LINE | awk -F: '{print $1}'
  GID=echo $LINE | awk -F: '{print $2}'
  addgroup -g $GID $NAME
done < "$GROUPFILE"

while IFS= read -r LINE
do
  NAME=echo $LINE | awk -F: '{print $1}'
  UID=echo $LINE | awk -F: '{print $2}'
  GRP=echo $LINE | awk -F: '{print $3}'
  if [ "$GRP" == "" ]; then
    GRP=$NAME
  fi
  addgroup -D -H -G $GRP -u $UID $NAME
done < "$USERSFILE"
